<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="添加订单地址"
        left-arrow
        @click-left="$router.back()"
      />
    </header>
    <div class="content">
      <van-address-edit
        :area-list="areaList"
        show-set-default
        save-button-text="保存并且使用该地址"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        
      />
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import { NavBar, AddressEdit } from 'vant'
import { areaList } from '@vant/area-data'
import { addAddress, updateOrderAddress ,  addressUP } from '@/api/order'
Vue.use(NavBar)
Vue.use(AddressEdit)
export default {
  data () {
    return {
      areaList: areaList
    }
  },
  methods: {
    onSave (content) {
      console.log(content)
      
      // 添加地址
      content.addressid = this.$route.query.addressid
      content.userid = localStorage.getItem('userid')
      addressUP(content).then(res => {
        console.log(res);
        this.$router.go(-1)
        // 添加地址成功
        // 修改订单地址并且返回确认订单页面
        // content.time = this.$route.params.time
        // updateOrderAddress(content).then((res1) => {
        //    console.log(res);
        //   // 修改成功返回确认订单页面
        //   this.$router.go(-2)
        // })
      })
    }
  },
  mounted () {
    console.log(this.$route);
     console.log(this.$route.query.addressid);
  }
}
</script>